<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class UnbindCard
{
    protected $id;

    public function __construct($uid, $title)
    {
        $this->id = $uid;
        $this->title = $title;
    }

    protected function script()
    {
        return <<<SCRIPT

layui.use('layer', function(){
        var layer = layui.layer;
        $('.unbind').click(function () {
           var that = this;
           var uid = $(that).attr('data-uid');
           var title = $(that).attr('data-title');
           layer.confirm('您确定要解绑'+ title + '的银行卡吗？', function(index){
              $.ajax({
                url: '/api/user/unbind/bankcard',
                type: 'post',
                data: {
                    uid: uid
                },
                success: function(res){
                    layer.msg('解绑成功');
                }
              });
              layer.close(index);
           });    
       });
});

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());
        return "&nbsp;<a href='javascript:void(0);'><button data-uid='{$this->id}'  data-title='{$this->title}' class='unbind layui-btn  layui-btn-warm layui-btn-xs'>卡</button></a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}